<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>数组拼接最小值</title>
</head>
<body>
	<script>
		function printMinNumber(arr) {
		  if (!arr || arr.length == 0) return null;
		  // sort底层是快排
		  return arr.sort(compare).join("");
		}
		// 找到ab 和 ba 这两种组合的最小值
		function compare(a, b) {
		  let front = `${a}${b}`;
		  let after = `${b}${a}`;
		  // 注意，这里相减会把字符串转成数字
		  return front - after;
		}

		let arr = [3, 54, 12];
		console.log(printMinNumber(arr)); // 12354
	</script>
</body>
</html>